home *** CD-ROM | disk | FTP | other *** search
/ PC Open 97 / PC Open 97 CD2.bin / Demo / FileMaker / Data1.cab / msdso_attrib.xslt4 < prev    next >
Encoding:
Extensible Markup Language  |  2002-05-24  |  4.0 KB  |  113 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.filemaker.com/fmpxmlresult">
  3. <!--
  4. File: msdso_attrib.xslt
  5.  
  6. Transforms data in an attribute based MSDSO grammar 
  7. into the FMPXMLRESULT grammar, suitable for import.
  8.  
  9. ===============================================================
  10.  
  11. Copyright ┬⌐ 2002 FileMaker, Inc.
  12. All rights reserved.
  13.  
  14. Redistribution and use in source and binary forms, with or
  15. without modification, are permitted provided that the following
  16. conditions are met:
  17.  
  18. * Redistributions of source code must retain the above copyright
  19.   notice, this list of conditions and the following disclaimer.
  20.  
  21. * Redistributions in binary form must reproduce the above copyright
  22.   notice, this list of conditions and the following disclaimer in 
  23.   the documentation and/or other materials provided with the
  24.   distribution.
  25.  
  26. * Neither the name of the FileMaker, Inc. nor the names of its 
  27.   contributors may be used to endorse or promote products derived
  28.   from this software without specific prior written
  29.   permission.
  30.  
  31. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  32. CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  33. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  34. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
  35. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 
  36. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
  37. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  38. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  39. BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  40. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  41. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  42. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  43.     
  44. ===============================================================
  45. -->
  46. <!-- 
  47. Root match template
  48.         
  49. This template begins the processing of the XML data, builds
  50. header of the FMPXMLRESULT grammar, and then calls the
  51. next template, METADATA.
  52.     -->
  53.     <xsl:template match="/">
  54.         <FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">
  55.             <ERRORCODE>0</ERRORCODE>
  56.             <PRODUCT BUILD="" NAME="" VERSION=""/>
  57.             <DATABASE DATEFORMAT="M/d/yyyy" LAYOUT="" NAME="" RECORDS="{count(/*/*)}" TIMEFORMAT="h:mm:ss a"/>
  58.             <xsl:call-template name="METADATA"/>
  59.         </FMPXMLRESULT>
  60.     </xsl:template>
  61. <!-- 
  62. Template:  METADATA
  63.         
  64. Builds the META section of the FMPXMLRESULT grammar.
  65. The xsl:attribute function is used to easily build an
  66. attribute element in the resulting XML file.
  67.     
  68. Notice the complex select statement used to handle
  69. each of the attributes in the XML input file.
  70.           
  71. The template RESULTSET is called once this template
  72. has completed its processing.
  73.     -->
  74.     <xsl:template name="METADATA" match="/*/*[1]">
  75.         <METADATA>
  76.             <xsl:for-each select="/*/*[1]/@*">
  77.                 <FIELD>
  78.                     <xsl:attribute name="EMPTYOK">YES</xsl:attribute>
  79.                     <xsl:attribute name="MAXREPEAT">1</xsl:attribute>
  80.                     <xsl:attribute name="NAME"><xsl:value-of select="name()"/></xsl:attribute>
  81.                     <xsl:attribute name="TYPE">TEXT</xsl:attribute>
  82.                 </FIELD>
  83.             </xsl:for-each>
  84.         </METADATA>
  85.         <xsl:call-template name="RESULTSET"/>
  86.     </xsl:template>
  87. <!-- 
  88. Template:  RESULTSET
  89.         
  90. Creates a ROW element with associated MODID and RECORDID
  91. attributes for each row in the input XML file. Attribute values in the
  92. input are mapped to COL elements with associated DATA values.
  93. -->
  94.     <xsl:template name="RESULTSET" match="/*/*">
  95.         <RESULTSET>
  96.             <xsl:attribute name="FOUND"><xsl:value-of select="count(/*/*)"/></xsl:attribute>
  97.             <xsl:for-each select="/*/*">
  98.                 <ROW>
  99.                     <xsl:attribute name="MODID">0</xsl:attribute>
  100.                     <xsl:attribute name="RECORDID">0</xsl:attribute>
  101.                     <xsl:for-each select="@*">
  102.                         <COL>
  103.                             <DATA>
  104.                                 <xsl:value-of select="."/>
  105.                             </DATA>
  106.                         </COL>
  107.                     </xsl:for-each>
  108.                 </ROW>
  109.             </xsl:for-each>
  110.         </RESULTSET>
  111.     </xsl:template>
  112. </xsl:stylesheet>
  113.